package com.eling.elcms.cater.webapp.controller;

import com.eling.elcms.cater.model.DishMenu;
import com.eling.elcms.cater.model.DishPrice;
import com.eling.elcms.cater.service.IDishMenuService;
import com.eling.elcms.core.dao.hibernate.search.SearchCondition;
import com.eling.elcms.core.webapp.controller.BaseFormController;
import com.eling.elcms.core.webapp.controller.Msg;
import com.eling.elcms.core.webapp.spring.ModelFilling;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
public class DishMenuController extends BaseFormController{
	@Autowired
	private IDishMenuService dishMenuService;
	
	@RequestMapping("/api/cate/dishmenu/search*")
	@ResponseBody
	public List<DishMenu> sreach(@ModelAttribute SearchCondition sc,@ModelAttribute DishMenu dishMenu) {
		sc.setQueryCondition(dishMenu);
		return dishMenuService.search(sc); 
	}
	
	@RequestMapping("/api/cate/dishmenu/query")
    @ResponseBody
    public List<DishMenu> query(@ModelAttribute DishMenu cond){
    	return dishMenuService.query(cond); 
    }
	
	@RequestMapping("/api/cate/dishmenu/save")
    @ResponseBody
    public DishMenu save(@ModelAttribute@ModelFilling DishMenu dishMenu) {
		return dishMenuService.save(dishMenu);
    }
	
	@RequestMapping("/api/cate/dishmenu/{pkDishMenu}/delete")
	@ResponseBody
	public Msg delete(@PathVariable Long pkDishMenu) {
		dishMenuService.remove(pkDishMenu);
	    return new Msg("删除成功");
	}
	
	/**查询一周菜单*/
	@RequestMapping("/api/cate/dishmenu/queryoneweek")
	@ResponseBody
	public List<DishMenu> queryOneWeek(@ModelAttribute DishMenu dishMenu){
		return dishMenuService.queryOneWeek(dishMenu);
	}
	
	/**保存单日菜单*/
	@RequestMapping("/api/cate/dishmenu/saveoneday")
	@ResponseBody
	public DishMenu saveOneDay(@RequestParam(value="string") String string,
			@ModelAttribute DishMenu dishMenu){
		return dishMenuService.saveOneDay(string,dishMenu);
	}
	
	/**清空当日菜单*/
	@RequestMapping("/api/cate/dishmenu/removeoneday")
	@ResponseBody
	public Msg removeOneDay(@ModelAttribute DishMenu dishMenu){
		dishMenuService.removeOneDay(dishMenu);
		return new Msg("删除成功"); 
	}
	
	/**复制到下周*/
	@RequestMapping("/api/cate/dishmenu/copytonextweek")
	@ResponseBody
	public Msg CopyToNextWeek(@ModelAttribute DishMenu dishMenu){
		dishMenuService.CopyToNextWeek(dishMenu);
		return new Msg("复制成功");
	}
	
	@RequestMapping("/api/cate/dishmenu/querytodaydish")
    @ResponseBody
    public List<DishPrice> querytodaydish(@ModelAttribute DishMenu cond){
    	return dishMenuService.querytodaydish(cond); 
    }
}
